import { orderCancel, orderConfirm } from "../../service/index.js"
import Dialog from '@vant/weapp/dialog/dialog';

Page({
  data: {
    order: {},
    dataType: ''
  },
  onLoad: function (options) {
    let order = JSON.parse(options.order);
    this.setData({
      order: order,
      dataType: order.state_text
    })
    console.log(this.data.dataType, this.data.order)
  },
  orderCancel: function () {
    Dialog.confirm({
      title: '友情提示',
      message: '确认取消订单吗？',
    }).then(() => {
      orderCancel({
        orderId: this.data.order.order_id
      }, (res) => {

        wx.navigateTo({
          url: '/pages/orders/index'
        })
      })
    })

  },
  orderConfirm: function () {
    Dialog.confirm({
      title: '友情提示',
      message: '收到商品了吗？',
    })
      .then(() => {
        orderConfirm({
          orderId: this.data.order.order_id
        }, (res) => {
          wx.showToast({ title: res.message, icon: 'success' })
          wx.navigateTo({
            url: '/pages/orders/index'
          })
        })
      })
      .catch(() => {
        console.log(22222)
      });
  },
  pj: function () {
    console.log('评价')
  }
});
